import React, { memo, useCallback } from 'react';
import { Button, message } from 'antd';

import { isSuccess } from '@/utils/request';
import { hrRecheck } from '@/services/salaryManage/salaryCalculate';
import _ from 'lodash';

const { updateData } = hrRecheck;

// 更新数据
const UpdateCheck = memo(({ handleItem, year, organizationCode, month, selectedRows, updateStateFn }) => {
    const handleFn = useCallback(async () => {
        const upRes = await updateData({
            year,
            month,
            organizationCode,
            salaryPayrollIdList: _.map(selectedRows, 'id')
        })
        if (isSuccess(upRes)) {
            message.success(upRes.msg);
            updateStateFn()
        } else {
            message.error(upRes.msg);
        }
    }, [month, organizationCode, selectedRows, updateStateFn, year]);


    return (
        <Button key={handleItem.code} onClick={handleFn}>
            {handleItem.name}
        </Button>
    );
});

export default memo(UpdateCheck)
